﻿using System.Drawing;

namespace HAOest.Forms.Mouse
{
    /// <summary>
    /// 鼠标拖动类
    /// </summary>
    public class MouseDrag : MouseAction
    {
        private int startMousePositionX;//鼠标点下时的X坐标
        private int startMousePositionY;//鼠标点下时的Y坐标
        private int startFormPositionX;//鼠标点下时窗口位置的X坐标
        private int startFormPositionY;//鼠标点下时窗口位置的Y坐标

        /// <summary>
        /// 鼠标拖动
        /// </summary>
        /// <param name="form">传入的窗口</param>
        public MouseDrag(System.Windows.Forms.Form form)
        {
            Point point = Functions.GetMousePosition();
            startMousePositionX = point.X;
            startMousePositionY = point.Y;
            startFormPositionX = form.Location.X;
            startFormPositionY = form.Location.Y;
        }

        /// <summary>
        /// 执行鼠标拖动
        /// </summary>
        /// <param name="form">传入的窗口</param>
        public override void Action(System.Windows.Forms.Form form)
        {
            Point point = Functions.GetMousePosition();
            form.Location = new Point(startFormPositionX + point.X - startMousePositionX, startFormPositionY + point.Y - startMousePositionY);
        }
    }
}
